import router from '../router/index'
import Vue from 'vue'
import { userLogin } from '@/api/user'
export default {
  namespaced: true,
  state: () => ({
    userInfo: null
  }),



  mutations: {
    initMut(state, obj) {
      state.userInfo = obj,
        localStorage.setItem('userInfo', JSON.stringify(obj))//用户存储在本地
      router.push('/')
    },
  },


  actions: {
    loginAction(context, data) {
      userLogin(data).then(res => { //获取后端下发过来的数据
        console.log(res);
        let { code, data } = res.data
        if (code == 1) {
          context.commit('initMut', data)
        }
      })
    },
  }
}